fix(cli): keep pending-queue previews on one terminal row - #3841
Open
Sma1lboy wants to merge 1 commit into
Open
Conversation
M4n5ter
force-pushed
the
fix/pending-queue-single-row
branch
from
August 26, 2026 08:53
51162dd to
f1ea9d4
Compare
`limitText` appends its truncation suffix behind a newline, so `firstLinePreview` returned a two-row string for any queued message whose first line exceeds 200 characters. Every element a layout component returns must occupy exactly one terminal row: pi-tui writes them between explicit CRLF separators and counts one row each, so the embedded newline shifted every later row down while the diff accounting still believed one row was written. `fitLine` cannot catch this — pi-tui's `visibleWidth` treats the newline as zero-width, so a 232-column line reads as fitting inside a 240-column terminal and is passed through untouched. Collapse the preview the way the sibling call site in `pi-transcript-tools.ts` already collapses the same `limitText` output. Generated-by: Claude Opus 5
M4n5ter
force-pushed
the
fix/pending-queue-single-row
branch
from
August 26, 2026 09:57
f1ea9d4 to
b2c2836
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
limitTextappends its truncation suffix behind a newline, sofirstLinePreviewreturned a two-row string for any queued message whose first line exceeds 200 characters — despite its own contract saying "trimmed for a one-line preview".Every element a layout component returns must occupy exactly one terminal row. pi-tui writes them between explicit CRLF separators and counts one row each, so the embedded newline shifts every later row down while the diff accounting still believes one row was written.
fitLinecannot defend against this: pi-tui'svisibleWidthtreats the newline as zero-width, so the composed line measures 232 columns and reads as fitting inside a 240-column terminal.The fix collapses the preview exactly the way the sibling call site at
pi-transcript-tools.ts:98already collapses the samelimitTextoutput.limitTextitself is unchanged — its multiline suffix is correct for the block contexts that use it.Fixes #3824
Verification
npm run lint,npm run format:check,npm --workspace maka-agent run typecheck, andnode --test packages/cli/dist/__tests__/pi-transcript.test.js(78/78) all pass. The new test was confirmed RED before the fix by revertingfirstLinePreviewand rebuilding.Captured live in a 240×20 tmux pane, driving the real
MakaPiLayoutComponentandMakaPendingQueueComponentthrough the real pi-tuiTuiMainScreenagainst a real terminal. Only the editor is stubbed, at a fixed one-row height, so it cannot itself be the source of drift.Before — the queued message occupies rows 16 and 17:
After — one element, one row:
Row accounting across a width scan, before → after:
The newline survives at widths 211–320 and at no width below 211 — below that,
fitLinetruncates before the newline lands, which is why narrow terminals never showed this. That matches the "roughly ≥210 columns" note in the issue.Review focus
The issue states the misalignment persists frame to frame until the queue drains. I have the row-count mismatch on screen and the code path (
pi-tui-layout.ts:174sizes the viewport frompendingLines.length), but I did not reproduce accumulating drift across incremental renders — pi-tui full-redraws each frame in my harness, which self-heals. The fix addresses the contract violation that causes it; I am flagging the gap rather than claiming more than I observed.The issue also suggests defense-in-depth by stripping
\r?\nin the layout component. I left that out: it would mask future contract violations at the boundary rather than at the call site that creates them, and every other producer already collapses correctly. Happy to add it if a maintainer prefers the belt-and-braces.AI use
Select exactly one:
Tool(s) and scope: Claude Opus 5 (Claude Code) — investigation, the fix, the regression test, and the tmux reproduction harness. Reviewed and verified locally by me; the affected commit carries a
Generated-bytrailer.Checklist
Does this PR entail a change in behavior?